package java实验七;
public class TV {
    boolean on = false;      // Default volume level is 1
    int channel = 1;         // IV is off
    
    public void turnOn() {
        on = true;
    }

    public void turnOff() {
        on = false;
    }

    public void setChannel(int newChannel) {
        if (on && newChannel >= 1 && newChannel <= 7)
            channel = newChannel;
    }

    public void setVolume(int newVolumeLevel) {
        if (on && newVolumeLevel >= 1 && newVolumeLevel <= 7)
            volumeLevel = newVolumeLevel;
    }

    public void channelUp() {
        if (on && channel > 1)
            channel++;
    }

    public void channelDown() {
        if (on && channel > 1)
            channel--;
    }

    public void volumeUp() {
        if (on && volumeLevel < 7)
            volumeLevel++;
    }

    public void volumeDown() {
        if (on && volumeLevel > 1)
            volumeLevel--;
    }

    public boolean isOn() {
        return on;
    }

    public int getChannel() {
        return channel;
    }

    public int getVolumeLevel() {
        return volumeLevel;
    }

    private int volumeLevel = 1;

    // 类TV的构造函数
    public TV() {
        on = false;
        volumeLevel = 1;
    }

    // 类TV的构造函数
    public TV(boolean on, int channel, int volumeLevel) {
        this.on = on;
        this.channel = channel;
        this.volumeLevel = volumeLevel;
    }
    public static void main(String args[])
{
	TV tv1 =new TV();
	tv1.turnOn();
	tv1.setChannel(30);
	tv1.setVolume(3);
	TV tv2 =new TV();
	tv2.turnOn();
	tv2.channelUp();
	tv2.channelUp();
	tv2.volumeUp();
	System.out.println("tv1's channel is "+tv1.channel + " and volume level is "+tv1.volumeLevel);
	System.out.println("tv2's channel is "+tv2.channel + " and volume level is "+tv2.volumeLevel);
	
	
}

}
